home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / plnk081.zip / pilot-link.0.8.1 / Java / Pdapilot-JDK-1.1 / Char4.java next >
Text File  |  1997-08-06  |  1KB  |  67 lines

  1.  
  2. package Pdapilot;
  3.  
  4. public class Char4 {
  5.     private int value;
  6.     private byte[] b;
  7.     
  8.     public Char4(int id) {
  9.         this.set(id);
  10.     }
  11.  
  12.     public Char4(String id) {
  13.         this.set(id);
  14.     }
  15.  
  16.     public Char4(byte[] b) throws java.lang.CloneNotSupportedException {
  17.         this.set(b);
  18.     }
  19.     
  20.     public Char4() {
  21.         this.set(0);
  22.     }
  23.     
  24.     public void set(int id) {
  25.         value = id;
  26.         b = new byte[4];
  27.         b[3] = (byte)(id & 0xff); id >>= 8;
  28.         b[2] = (byte)(id & 0xff); id >>= 8;
  29.         b[1] = (byte)(id & 0xff); id >>= 8;
  30.         b[0] = (byte)(id & 0xff); id >>= 8;
  31.     }
  32.  
  33.     public void set(String id) {
  34.         byte[] by = id.getBytes();
  35.         try {
  36.             this.set(by);
  37.         } catch(java.lang.CloneNotSupportedException e) {
  38.             /* Don't be silly! */
  39.         }
  40.     }
  41.     
  42.     public void set(byte[] b) throws java.lang.CloneNotSupportedException{
  43.         this.b = (byte[])b.clone();
  44.         value = (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3];
  45.     }
  46.     
  47.     public int getInt() {
  48.         return value;
  49.     }
  50.     
  51.     public byte[] getBytes() {
  52.         return b;
  53.     }
  54.  
  55.     public String getString() {
  56.         return new String(b, 0, b.length);
  57.     }
  58.     
  59.     public boolean equals(Char4 other) {
  60.         return (value == other.value);
  61.     }
  62.     
  63.     public String toString() {
  64.         return Util.prettyPrint(b);
  65.     }
  66. }
  67.